/************************************************************************
 * @file ConfigPanelManager.cpp
 * @author Ian Chen
 * @version 1.0
 *
 * @section LICENSE
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
 * General Public License for more details at
 * http://www.gnu.org/licenses/lgpl.html
 *
 ************************************************************************/
#include <pluginui/manager/ConfigPanelManager.h>

namespace antu
{
namespace plugin
{
namespace ui
{
const char* ConfigPanelManager::Name = "CONFIG_PANEL_MANAGER";

ConfigPanelManager::ConfigPanelManager()
{
}

ConfigPanelManager::~ConfigPanelManager()
{
    auto iter = this->m_oItems.begin();
    auto end = this->m_oItems.end();

    for (; iter != end; iter++)
    {
        delete iter->pPanel;
    }
}

size_t ConfigPanelManager::size() const
{
    return this->m_oItems.size();
}

ConfigPanelItemStruct ConfigPanelManager::at(size_t index)
{
    if (index < 0 || index >= this->m_oItems.size())
        return ConfigPanelItemStruct();

    return this->m_oItems.at(index);
}

void ConfigPanelManager::addItem(ConfigPanelItem &item)
{
    Q_ASSERT(!item.isNull());
    this->m_oItems.push_back(item);
}

void ConfigPanelManager::addItem(const QIcon &icon, const QString &title, ConfigPanel *pPanel)
{
    ConfigPanelItem item;

    item.icon = icon;
    item.title = title;
    item.pPanel = pPanel;

    this->addItem(item);
}
}
}
}
